<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <!-- 计算属性完整写法
   计算属性默认的简写，只能读取访问，不能修改
   如果要“修改”->需要写计算属性的完整写法 -->
   <div id="app">
    姓：<input type="text"><br>
    名：<input type="text"><br>
    <p>姓名：</p>
    <button>{{fullName}}</button>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>

  <script>
    const app = new Vue({
      el: '#app',
      data: {
        firstName:'刘',
        lastName: '备'
      },
      computed: {
        //简写->获取
        /* fullName() {
          return this.firstName + this.lastName
        } */
       fullName: {
        //(1)当fullName计算属性，被获取求值时，执行get（有缓存，优先读缓存）
        //会将返回值作为求值的结果
        get() {
          return this.firstName + this.lastName
        },
        //(2)当fullName计算属性，被修改赋值时，执行set
        //修改的值，传递给set方法的形参
        set(value) {
          this.firstName = value.slice(0, 1)
          this.lastName = value.slice(1)
        }
       }
      },
      methods: {
        changeName() {
          this.fullName = '吕小布'
        }
      }
    })
  </script>
</body>
</html>